#include <stdio.h>
#include "uthash-1.9.7/uthash.h"
#include "uthash-1.9.7/utlist.h"
#include <stdlib.h>
#include <unistd.h>
typedef struct hash_test{
	int id;
	struct UT_hash_handle hh;
	int null;
}item;
item *header=NULL;
#define OFFSET(types,field) (&(((types*)0)->field))
int main()
{
	item i1={0};
	i1.id=1;
	printf("address=%p\n",&i1);
	HASH_ADD_INT(header,id,(item*)&i1);
	item i2={0};
	i2.id=2;
	printf("address=%p\n",&i2);
	HASH_ADD_INT(header,id,&i2);
	item i3={0};
	i3.id=3;
	printf("address=%p\n",&i3);
	HASH_ADD_INT(header,id,&i3);
	item i4={0};
	i4.id=4;
	printf("address=%p\n",&i4);
	HASH_ADD_INT(header,id,&i4);
	printf("header=%p table=%p\n",header,(header->hh).tbl);
	printf("num items=%d\n",(header->hh).tbl->num_items);
	struct UT_hash_handle *tail=(header->hh).tbl->tail;
	printf("next=%p\n",tail->next);
	printf("offset=%d\n",OFFSET(item,hh));
	char *ptr=(char*)tail;
	int offset=(int)OFFSET(item,hh);
	item *i=(item*)(ptr-offset);
	while(NULL!=i){
		printf("address=%p\n",i);
		printf("id=%d\n",i->id);
		i=i->hh.prev;
	}
	int v=1;
	HASH_FIND_INT(header,&v,i);
	HASH_DEL(header,i);
	printf("header=%p\n",header);
	v=2;
	HASH_FIND_INT(header,&v,i);
	HASH_DEL(header,i);
	printf("header=%p\n",header);
	v=3;
	HASH_FIND_INT(header,&v,i);
	HASH_DEL(header,i);
	printf("header=%p\n",header);
	v=4;
	HASH_FIND_INT(header,&v,i);
	HASH_DEL(header,i);
	printf("header=%p\n",header);
}
